<style lang="less" scoped>
  .f-mt10 {
    margin-top: 10px;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .f-mb10 {
    margin-bottom: 20px;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

  .f-w70 {
    width: 70%;
  }

  .f-w125 {
    width: 125%;
  }

  .f-w100 {
    width: 100%;
  }

  .my {
    margin-left: -60px;
  }

  .f-w120 {
    width: 120%;
  }

  .width70 {
    width: 70%;
  }

  .el-dialog {
    flex: 1;
    .isreceipt {
      display: none;
    }
    .receipt {
      display: inline-block;
    }
  }

  .backcolor {
    background-color: aqua
  }

  .f-w80 {
    position: absolute;
    margin-top: -6px;
    width: 80px;
  }
</style>

<template>
  <section>
    <!--工具条-->
    <!--工具条-->
    <search-bar more-display>
      <el-row>

        <el-col :span="8">
          <el-form-item label="申请开票时间">
            <el-date-picker
              v-model="searchCreateDate"
              type="daterange"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="开票状态">
            <el-select  v-model="searchCondition.EQ_billingStatus"
                       placeholder="请选择">
              <el-option
                v-for="item in $store.getters.BILLING_STATUS"
                :key="item.dictVal"
                :label="item.cnDictValname"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="发票号码">
            <el-input
                      v-model="searchCondition.LIKE_taxsheetNo" placeholder="请输入发票号码"></el-input>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="税费支付状态">
            <el-select  v-model="searchCondition.EQ_taxationPayStatus"
                       placeholder="请选择">
              <el-option
                v-for="item in $store.getters.ORDER_PAY_STATUS"
                :key="item.dictVal"
                :label="item.cnDictValname"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="发票类型">
            <el-select  v-model="searchCondition.EQ_taxsheetType"
                       placeholder="请选择">
              <el-option
                v-for="item in $store.getters.TAXSHEET_TYPE"
                :key="item.dictVal"
                :label="item.cnDictValname"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

    </search-bar>
    <!-- 操作 -->
    <el-col :span="24" style="margin-bottom: 10px">
      <el-button type="primary" @click="handleAdd">申请开票</el-button>
      <el-button type="primary" @click="myReset" style="float: right">重置</el-button>
      <el-button type="primary" @click="searchTaxsheet" style="float: right">查询</el-button>
    </el-col>

    <!--我的发票列表-->
    <el-table :data="tableData" highlight-current-row border @sort-change="sortChange"
              @selection-change="selsChange" v-loading="listLoading" style="width: 100%;">
      <el-table-column type="index" label="序号" width="100">
      </el-table-column>
      <el-table-column prop="createDate" label="申请开票时间" width="150" >
      </el-table-column>
      <el-table-column prop="appTaxsheetAmount" label="开票金额(元)" width="140" >
        <template slot-scope="scope">
          <label v-if=" scope.row.appTaxsheetAmount != null">
            {{Math.floor(scope.row.appTaxsheetAmount * 100) / 100}}
          </label>
        </template>
      </el-table-column>
      <el-table-column prop="taxationPayStatusName" label="税费支付" width="120" >
      </el-table-column>
      <el-table-column prop="taxReceivable" label="应收税费(元)" width="140" >
        <template slot-scope="scope">
          <label v-if=" scope.row.taxReceivable != null">
            {{Math.floor(scope.row.taxReceivable * 100) / 100}}
          </label>
        </template>
      </el-table-column>
      <el-table-column prop="" label="发票信息" width="180">
        <template slot-scope="scope">
          <li style="list-style-type:none;" class="f-font-20 f-mb5">
            {{scope.row.taxsheetTypeName}}
          </li>
          <li style="list-style-type:none;" class="f-font-20 f-mb5">
            {{scope.row.taxsheetTitle}}
          </li>
        </template>
      </el-table-column>
      <el-table-column prop="" label="邮寄信息">
        <template slot-scope="scope">
          <li style="list-style-type:none;" class="f-font-20 f-mb5">
            {{scope.row.consigneeName}}   {{scope.row.phone}}
          </li>
          <li style="list-style-type:none;" class="f-font-20 f-mb5">
            {{scope.row.collectAddress}}
          </li>
        </template>
      </el-table-column>
      <el-table-column prop="billingStatusName" label="开票状态" width="120" >
      </el-table-column>
      <el-table-column prop="taxsheetNo" label="发票号码" width="140" >
      </el-table-column>
      <el-table-column prop="billingDate" label="开票日期" width="120" >
        <template slot-scope="scope">
          <label v-if="scope.row.billingDate != null">
            {{scope.row.billingDate.toString().substring(0, 10)}}
          </label>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button  type="primary" v-if="scope.row.billingStatus !== 102014001"
                     @click="getEditBYId(scope.$index, scope.row)">详情
          </el-button>
          <el-button  type="primary"
                     v-if="scope.row.billingStatus === 102014002 && scope.row.taxReceivable >0  && scope.row.taxationPayStatus === 101003001"
                     @click="paymentConfirmation(scope.$index, scope.row)">支付税费
          </el-button>
          <el-button  type="primary" v-if="scope.row.billingStatus === 102014001"
                     @click="handleEdit(scope.$index, scope.row)">申请开票
          </el-button>
          <el-button v-if="scope.row.billingStatus === 102014001" type="danger"
                     @click="handleDel(scope.$index, scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :total="total" style="float: right">
      </el-pagination>
    </el-col>
    <!--支付税费弹窗-->
    <el-dialog title="支付税费" size="tiny" :visible.sync="paymentConfirmationDialog">
      <div style="background: #F2F2F2;">
        <el-row class="f-pt10 f-mb0">
          <el-col :span="12">
            <div class="grid-content f-ml10">本次开票金额：<label v-html="taxsheet.appTaxsheetAmount"></label></div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content">应付税费：<label v-html="taxsheet.taxReceivable"></label></div>
          </el-col>
        </el-row>
      </div>
      <el-row class="f-mb0" style="display: none">
        <el-col :span="24" class="f-ml10 f-mt10">
          <div class="grid-content bg-purple-dark">
            <el-radio class="radio" v-model="taxPayRadio" label="accountPay"> 账户余额：可支付余额: 0元
            </el-radio>
          </div>
        </el-col>
      </el-row>
      <el-row class="f-mb0">
        <el-col :span="24" class="f-ml10">
          <div class="grid-content bg-purple-dark">其他支付方式</div>
        </el-col>
      </el-row>
      <el-row style="background: #F2F2F2;">
        <el-col :span="24" class="f-mb20 f-ml10">
          <div class="grid-content bg-purple-dark">
            <div class="grid-content">
              <div>
                <p>请选择一下支付方式的一种</p>
                <el-row class="f-pb10 f-pl10">
                  <el-col :span="8">
                    <el-radio class="radio" v-model="taxPayRadio" label="aliPay">
                      <img src="../../assets/aliPayLogo.png" class="f-w80"></el-radio>
                  </el-col>
                  <el-col :span="8">
                    <el-radio class="radio" v-model="taxPayRadio" label="weChatPay"><img
                      src="../../assets/weChatLogo.png" class="f-w80"></el-radio>
                  </el-col>
                  <el-col :span="8">
                    <el-radio class="radio" v-model="taxPayRadio" label="unionPay"><img
                      src="../../assets/unionPayLogo.png" class="f-w80"></el-radio>
                  </el-col>
                </el-row>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
                <el-button @click="paymentConfirmationDialog = false" class="f-wa">取 消</el-button>
                <el-button type="primary" @click="paymentAffirms" class="f-wa">确 定</el-button>
            </span>
    </el-dialog>

    <!--&lt;!&ndash;申请开票弹窗 &ndash;&gt;-->
    <el-dialog :title="dialogTitle" size="large" :visible.sync="taxsheetVisible" :close-on-click-modal="false">
      <el-form :model="taxsheet" :rules="rules" label-width="110px" ref="taxsheet">
        <el-row class="f-mt10 f-mb10">
          <el-col :span="8">
            <el-form-item label="发票抬头" prop="taxsheetTitleId">
              <el-select :disabled="useEnTaxChecked==='1'"
                         v-model="taxsheet.taxsheetTitleId"
                         remote
                         :remote-method="searchTaxsheets"
                         @change="mySearchTaxsheet"
                         filterable
                         placeholder="请选择">
                <el-option v-for="(mu,index) in searchTaxshhetTest" :key="index" :label="mu.taxsheetTitle"
                           :value="mu.id">
                </el-option>
              </el-select>
              <el-checkbox class="f-ml10" true-label="1" false-label="0"
                           @change="setTaxsheetTypeClick" v-model="useEnTaxChecked" v-if="useEnTaxShow">使用企业增值税专用发票（图片）
              </el-checkbox>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="收件人" class="width70" prop="consigneeName">
              <el-input :disabled="useEnTaxChecked==='1'" v-model="taxsheet.consigneeName"
                        placeholder="请输入收件人名称"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="所在地区" class="width70" prop="myAddress">
              <address-select :disabled="useEnTaxChecked==='1'" v-model="taxsheet.myAddress"
                               placeholder="请选择地址"
                              class="f-w233"></address-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row class="f-mt10 f-mb10">
          <el-col :span="8">
            <el-form-item label="发票类型" prop="taxsheetType">
              <el-select :disabled="true"  @change="taxsheetTypeSelect" v-model="taxsheet.taxsheetType"
                         placeholder="请选择">
                <el-option
                  v-for="item in $store.getters.TAXSHEET_TYPE"
                  :key="item.dictVal"
                  :label="item.cnDictValname"
                  :value="item.dictVal">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="手机号" class="width70" prop="phone" :rules="[
            {required: true, message: '请输入手机号', trigger: 'change'},
            {min:11,max:11, message: '长度在11个字符', trigger: 'change'}
          ]">
              <el-input :disabled="useEnTaxChecked==='1'" type="number" v-model="taxsheet.phone"
                        placeholder="请输入手机号"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="街道" class="width70" prop="street">
              <el-input :disabled="useEnTaxChecked==='1'" v-model="taxsheet.street" placeholder="请输入街道"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 操作 -->
        <el-col :span="24" style="margin-bottom: 10px">
          <el-button type="primary" v-if="taxsheet.billingStatus == 102014001 || openStatus"
                     @click="addInvoiceDetail">添加对帐单
          </el-button>
          <el-button type="primary" v-if="taxsheet.billingStatus == 102014001 || openStatus"
                     @click="addOrderDetail">添加订单
          </el-button>
        </el-col>
        <!--我的发票详情列表-->
        <el-table :data="taxsheetDetails" highlight-current-row border
                  max-height="500"
                  :summary-method="getSummaries"
                  show-summary v-loading="listLoading1" style="width: 100%;">
          <el-table-column type="index" label="序号" width="100">
          </el-table-column>
          <el-table-column prop="documentTypeName" label="单据类型">
          </el-table-column>
          <el-table-column prop="documentNumber" label="单据编号" width="200">
          </el-table-column>
          <el-table-column prop="documentAmount" label="单据金额(元)" width="180">
            <template slot-scope="scope">
              <label v-if=" scope.row.documentAmount != null">
                {{Math.floor(scope.row.documentAmount * 100) / 100}}
              </label>
            </template>
          </el-table-column>
          <el-table-column prop="invoicedAmount" label="已开票金额(元)" width="180">
            <template slot-scope="scope">
              <label v-if=" scope.row.invoicedAmount != null">
                {{Math.floor(scope.row.invoicedAmount * 100) / 100}}
              </label>
            </template>
          </el-table-column>
          <el-table-column prop="currentInvoicedAmount" label="本次开票金额(元)" width="180">
            <template slot-scope="scope">
              <label v-if=" scope.row.currentInvoicedAmount != null">
                {{Math.floor(scope.row.currentInvoicedAmount * 100) / 100}}
              </label>
            </template>
          </el-table-column>
          <el-table-column prop="taxesAndFeesReceivable" label="本次应收税费(元)" width="180">
            <template slot-scope="scope">
              <label v-if=" scope.row.taxesAndFeesReceivable != null">
                {{Math.floor(scope.row.taxesAndFeesReceivable * 100) / 100}}
              </label>
            </template>
          </el-table-column>

          <el-table-column label="操作" width="250">
            <template slot-scope="scope">
              <el-button type="danger"
                         @click="handleTaxsheetDel(scope.$index,scope.row,taxsheetDetails)"
                         v-if="openStatus || taxsheet.billingStatus == 102014001  "
              >删除
              </el-button>
              <el-button type="primary"  @click="openMonen(scope.$index,scope.row)"
                         v-if="scope.row.isDel && scope.row.documentType ===102015001"
              >开票金额
              </el-button>
            </template>
          </el-table-column>
        </el-table>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="taxsheet.billingStatus == 102014001 || openStatus"
                   @click.native="taxsheetVisible = false">取消
        </el-button>
        <el-button v-if="taxsheet.billingStatus == 102014001 || openStatus" type="primary"
                   @click.native="handleSubmit" :loading="submitLoading">保存
        </el-button>
        <el-button v-if="taxsheet.billingStatus == 102014001 || openStatus" type="primary"
                   @click.native="saveDetailSubmit" :loading="submitLoading">提交申请
        </el-button>
      </div>
    </el-dialog>

    <!--开票金额弹窗-->
    <el-dialog :title="openInvoiceMoneyTitle" size="tiny" :visible.sync="openInvoiceMoneyVisible"
               :close-on-click-modal="false">
      <el-form label-width="150px" :model="openTaxSheet" ref="openTaxSheet">
        <el-row class="f-mt10 f-mb10">
          <el-col :span="24">
            <el-form-item label="可开票含税金额" class="width70">
              <label>{{ Math.floor(this.currentTaxMayBeInvoiced * 100) / 100}} 元</label>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row class="f-mt10 f-mb10">
          <el-col :span="24" class="width70">
            <el-form-item label="开票金额"
                          prop="currentOpenMoney"
                          :rules="{type:'number', required: true, message: '请输入开票金额', trigger: 'blur' }"
            >
              <el-input type="number" v-model.number="openTaxSheet.currentOpenMoney" placeholder="请输入开票金额"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="openInvoiceMoneyVisible = false">取消</el-button>
        <el-button type="primary" @click.native="saveOpenMoney()">保存</el-button>
      </div>
    </el-dialog>
    <!--添加 订单弹窗 -->
    <el-dialog :title="orderTitle" size="large" :visible.sync="orderVisible" :close-on-click-modal="false">
      <!--订单列表-->
      <el-table :data="orderData" highlight-current-row border @sort-change="sortChange1"
                @selection-change="selsChange1" v-loading="listLoading2" style="width: 100%;">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="orderNumber" label="订单编号" width="180" >
        </el-table-column>
        <el-table-column label="下单日期" width="150" >
          <template slot-scope="scope">
            <label v-if="scope.row.createDate != null">
              {{scope.row.createDate.toString().substring(0, 10)}}
            </label>
          </template>
        </el-table-column>

        <el-table-column prop="orderPrice" label="订单金额(元)" width="250" >
        </el-table-column>
        <el-table-column prop="orderStatusName" label="订单状态" width="120" >
        </el-table-column>
        <el-table-column label="货物信息" width="180" >
          <template slot-scope="scope">
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.orderName}}
            </li>
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.amount}}件
            </li>
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.weight}}吨
            </li>
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.volume}}方
            </li>
          </template>
        </el-table-column>
        <el-table-column label="收货人信息" >
          <template slot-scope="scope">
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.sendContactName}}
            </li>
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.sendContactPhone}}
            </li>
            <li style="list-style-type:none;" class="f-font-20 f-mb5">
              {{scope.row.sendProvince}} {{scope.row.sendCity}} {{scope.row.sendCounty}} {{scope.row.sendStreet}}
            </li>
          </template>
        </el-table-column>
      </el-table>
      <!--工具条-->
      <el-col :span="24" class="toolbar">
        <el-pagination
          :current-page="currentPage1"
          :page-size="pageSize1"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"
          layout="total,sizes,prev, pager, next, jumper"
          :total="total1" style="float: right">
        </el-pagination>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="orderVisible = false">取消</el-button>
        <el-button type="primary" @click.native="orderSave" :loading="listLoading2">保存</el-button>
      </div>
    </el-dialog>

    <!--添加 对帐单弹窗 -->
    <el-dialog :title="invoiceTitle" size="large" :visible.sync="invoiceVisible" :close-on-click-modal="false">
      <!--对帐单列表-->
      <el-table :data="invoiceData" highlight-current-row border @sort-change="sortChange2"
                @selection-change="selsChange2" v-loading="listLoading4" style="width: 100%;">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column label="对帐单周期" width="250" >
          <template slot-scope="scope">
            <label>
              {{scope.row.invoicePeriodStart}} 至 {{scope.row.invoicePeriodEnd}}
            </label>
          </template>
        </el-table-column>

        <el-table-column prop="invoiceNumber" label="对帐单编号" width="250" >
        </el-table-column>
        <el-table-column prop="createDate" label="出帐日期" width="120" >
        </el-table-column>
        <el-table-column prop="invoiceTotalAmount" label="帐单金额" width="180" >
        </el-table-column>
        <el-table-column prop="amountToBeInvoiced" label="可开票金额" >
        </el-table-column>
        <el-table-column prop="paidAmount" label="已付金额" >
        </el-table-column>
        <el-table-column prop="residueAmount" label="未付金额" >
        </el-table-column>
        <el-table-column prop="paymentDate" label="结算日期" >
        </el-table-column>
        <el-table-column prop="invoiceStatusName" label="付款状态" >
        </el-table-column>

      </el-table>
      <!--工具条-->
      <el-col :span="24" class="toolbar">
        <el-pagination
          :current-page="currentPage2"
          :page-size="pageSize2"
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"
          layout="total,sizes,prev, pager, next, jumper"
          :total="total2" style="float: right">
        </el-pagination>
      </el-col>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="invoiceVisible = false">取消</el-button>
        <el-button type="primary" @click.native="saveInvoice" :loading="listLoading4">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="请使用微信客户端扫一扫支付" :visible.sync="wechatQRCodeDialog"
               size="tiny">
      <div v-html="QRCodehtml">
      </div>
    </el-dialog>
    <!----详情-->
    <el-dialog :title="openBillTitle"  :visible.sync="openBillVisible" :close-on-click-modal="false">
      <el-form :model="taxsheet" label-width="110px" ref="taxsheet">
        <!--个人普通发票-->
        <div v-if="taxsheet.taxsheetType === 102013001">

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票类型" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetTypeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票抬头" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetTitle"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="收件人" class="width70">
                <el-input :disabled="true" v-model="taxsheet.consigneeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="手机号" class="width70">
                <el-input :disabled="true" v-model="taxsheet.phone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="收件地址" class="width70">
                <el-input :disabled="true" v-model="taxsheet.collectAddress"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!--我的发票详情列表-->
          <el-table :data="taxsheetDetails" highlight-current-row border
                    max-height="500"
                    :summary-method="getSummaries"
                    show-summary v-loading="listLoading4" style="width: 100%;">
            <el-table-column type="index" label="序1号" width="100">
            </el-table-column>
            <el-table-column prop="documentTypeName" label="单据类型">
            </el-table-column>
            <el-table-column prop="documentNumber" label="单据编号" width="200">
            </el-table-column>
            <el-table-column prop="documentAmount" label="单据金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.documentAmount != null">
                  {{Math.floor(scope.row.documentAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="currentInvoicedAmount" label="本次开票金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.currentInvoicedAmount != null">
                  {{Math.floor(scope.row.currentInvoicedAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="taxesAndFeesReceivable" label="本次应收税费(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.taxesAndFeesReceivable != null">
                  {{Math.floor(scope.row.taxesAndFeesReceivable * 100) / 100}}
                </label>
              </template>
            </el-table-column>

          </el-table>

        </div>
        <!--单位普通发票-->
        <div v-if="taxsheet.taxsheetType === 102013002">

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票类型" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetTypeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票抬头" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetTitle"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="收件人" class="width70">
                <el-input :disabled="true" v-model="taxsheet.consigneeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="手机号" class="width70">
                <el-input :disabled="true" v-model="taxsheet.phone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="收件地址" class="width70">
                <el-input :disabled="true" v-model="taxsheet.collectAddress"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!--我的发票详情列表-->
          <el-table :data="taxsheet.taxsheetDetails" highlight-current-row border
                    max-height="500"
                    :summary-method="getSummaries"
                    show-summary v-loading="listLoading4" style="width: 100%;">
            <el-table-column type="index" label="序1号" width="100">
            </el-table-column>
            <el-table-column prop="documentTypeName" label="单据类型">
            </el-table-column>
            <el-table-column prop="documentNumber" label="单据编号" width="200">
            </el-table-column>
            <el-table-column prop="documentAmount" label="单据金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.documentAmount != null">
                  {{Math.floor(scope.row.documentAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="taxMayBeInvoiced" label="可开票含税金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.taxMayBeInvoiced != ''">
                  {{Math.floor(scope.row.taxMayBeInvoiced * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="invoicedAmount" label="已开票金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.invoicedAmount != null">
                  {{Math.floor(scope.row.invoicedAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="currentInvoicedAmount" label="本次开票金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.currentInvoicedAmount != null">
                  {{Math.floor(scope.row.currentInvoicedAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="taxesAndFeesReceivable" label="本次应收税费(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.taxesAndFeesReceivable != null">
                  {{Math.floor(scope.row.taxesAndFeesReceivable * 100) / 100}}
                </label>
              </template>
            </el-table-column>
          </el-table>

        </div>
        <!--单位增值 税发票-->
        <div v-if="taxsheet.taxsheetType === 102013003">

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票类型" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetTypeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票抬头" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetTitle"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="纳税人识别号" class="width70">
                <el-input :disabled="true" v-model="invoiceManage.taxpayersRegistrationNumber"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="开户银行名称" class="width70">
                <el-input :disabled="true" v-model="invoiceManage.openingBank"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="开户银行账户" class="width70">
                <el-input :disabled="true" v-model="invoiceManage.bankAccount"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="注册登记地址" class="width70">
                <el-input :disabled="true" v-model="invoiceManage.registerLocalHost"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="公司电话" class="width70">
                <el-input :disabled="true" v-model="invoiceManage.companyTelphone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="12">
              <el-form-item label="营业执照">
                <el-upload
                  class="avatar-uploader"
                  action=""
                  :disabled="true"
                  :show-file-list="false"
                >
                  <img width="75%" v-if="oldHeadUrl && invoiceManage.businessLicenseUrl"
                       :src="decodeURI(invoiceManage.httpHead+invoiceManage.businessLicenseUrl)"
                       class="avatar">
                  <img v-else-if="!oldHeadUrl && tempCurrentHeadUrl" :src="tempCurrentHeadUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="一般纳税人证明">
                <el-upload
                  :disabled="true"
                  class="avatar-uploader"
                  action=""
                  :show-file-list="false"
                >
                  <img width="75%" v-if="oldHeadUrl && invoiceManage.taxpayerProveUrl"
                       :src="decodeURI(invoiceManage.httpHead+invoiceManage.taxpayerProveUrl)"
                       class="avatar">
                  <img v-else-if="!oldHeadUrl && tempCurrentHeadUrl" :src="tempCurrentHeadUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="收件人" class="width70">
                <el-input :disabled="true" v-model="taxsheet.consigneeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="手机号" class="width70">
                <el-input :disabled="true" v-model="taxsheet.phone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="收件地址" class="width70">
                <el-input :disabled="true" v-model="invoiceManage.collectAddress"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!--我的发票详情列表-->
          <el-table :data="taxsheet.taxsheetDetails" highlight-current-row border
                    max-height="500"
                    :summary-method="getSummaries"
                    show-summary v-loading="listLoading4" style="width: 100%;">
            <el-table-column type="index" label="序号" width="100">
            </el-table-column>
            <el-table-column prop="documentTypeName" label="单据类型">
            </el-table-column>
            <el-table-column prop="documentNumber" label="单据编号" width="200">
            </el-table-column>
            <el-table-column prop="documentAmount" label="单据金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.documentAmount != null">
                  {{Math.floor(scope.row.documentAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="taxMayBeInvoiced" label="可开票含税金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.taxMayBeInvoiced != ''">
                  {{Math.floor(scope.row.taxMayBeInvoiced * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="invoicedAmount" label="已开票金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.invoicedAmount != null">
                  {{Math.floor(scope.row.invoicedAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="currentInvoicedAmount" label="本次开票金额(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.currentInvoicedAmount != null">
                  {{Math.floor(scope.row.currentInvoicedAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="taxesAndFeesReceivable" label="本次应收税费(元)" width="180">
              <template slot-scope="scope">
                <label v-if=" scope.row.taxesAndFeesReceivable != null">
                  {{Math.floor(scope.row.taxesAndFeesReceivable * 100) / 100}}
                </label>
              </template>
            </el-table-column>

          </el-table>
        </div>

        <!--企业增值税发票图片-->
        <div v-if="taxsheet.taxsheetType === 102013004">
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票类型" class="width70">
                <el-input :readonly="true" v-model="taxsheet.taxsheetTypeName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <img width="90%" v-bind:src="taxsheet.httpHead+taxsheet.enterpriseValueAddedTaxUrl">
            </el-col>
          </el-row>
          <!--我的发票详情列表-->
          <el-table :data="taxsheet.taxsheetDetails" highlight-current-row border
                    max-height="500"
                    :summary-method="getSummaries"
                    show-summary v-loading="listLoading3" style="width: 100%;">
            <el-table-column type="index" label="序号" width="100">
            </el-table-column>
            <el-table-column prop="documentTypeName" label="单据类型">
            </el-table-column>
            <el-table-column prop="documentNumber" label="单据编号" width="200">
            </el-table-column>
            <el-table-column prop="documentAmount" label="单据金额(元)" width="150">
              <template slot-scope="scope">
                <label v-if=" scope.row.documentAmount != null">
                  {{Math.floor(scope.row.documentAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="currentInvoicedAmount" label="本次开票金额(元)" width="150">
              <template slot-scope="scope">
                <label v-if=" scope.row.currentInvoicedAmount != null">
                  {{Math.floor(scope.row.currentInvoicedAmount * 100) / 100}}
                </label>
              </template>
            </el-table-column>
            <el-table-column prop="taxesAndFeesReceivable" label="本次应收税费(元)" width="150">
              <template slot-scope="scope">
                <label v-if=" scope.row.taxesAndFeesReceivable != null">
                  {{Math.floor(scope.row.taxesAndFeesReceivable * 100) / 100}}
                </label>
              </template>
            </el-table-column>

          </el-table>
        </div>

          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="发票号码" class="width70">
                <el-input :disabled="true" v-model="taxsheet.taxsheetNo"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="开票日期" class="width70">
                <el-input :disabled="true" v-model="taxsheet.billingDate"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="备注" class="width70">
                <el-input type="textarea" :disabled="true" v-model="taxsheet.remark"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="f-mt10 f-mb10">
            <el-col :span="24">
              <el-form-item label="确认开票上传的图片">
                <el-upload
                  action=""
                  :disabled="true"
                  class="avatar-uploader"
                  :show-file-list="false"
                >
                  <img width="75%" v-if="oldHeadUrl && taxsheet.taxsheetPhotoUrl"
                       :src="decodeURI(taxsheet.httpHead+taxsheet.taxsheetPhotoUrl)"
                       class="avatar">
                  <img v-else-if="!oldHeadUrl && tempCurrentHeadUrl" :src="tempCurrentHeadUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>

      </el-form>
    </el-dialog>

  </section>
</template>

<script>
import {searchByUserId} from '../../api/clearing/invoice.js';
import {
  searchInvoiceManage,
  getInvoiceManage,
  getTaxsheetTitleEnValueAddedTax
} from '../../api/meb-user/TaxsheetTitle.js';
import {
  searchAddValue
} from '../../api/freight/addValue';
import {
  searchTaxsheet,
  saveTaxsheet,
  delTaxsheet,
  saveTaxsheetSubmit,
  aliPay,
  accountPay,
  unionPay,
  wechatPay,
  payments,
  getTaxsheet
} from '../../api/meb-user/TaxSheet.js';
import {
  searchOrderForInvoice
} from '../../api/order/order.js';
import {objToFilter, resetObjNull, getSelectObect, uniqeByKeys, resetForm, isEmpty} from '../../lib/util';

export default {
  data () {
    return {
      isActive: false,
      taxsheetTitleEnValueAddedTaxObj: {},
      useEnTaxChecked: 0,
      useEnTaxShow: false,
      oldHeadUrl: true,
      tempCurrentHeadUrl: '',
      currentOpenMoneyIndex: '',
      currentTaxMayBeInvoiced: '',
      currentOpenMoneyIndexMoney: '',
      openTaxSheet: {
        currentOpenMoney: ''
      },
      cruuendTable: [],
      stopPayWeChat: '',
      QRCodehtml: '',
      wechatQRCodeDialog: false,
      currentTaxsheetId: '',
      paymentConfirmationDialog: false,
      taxPayRadio: '', // 税费支付单选框
      searchCreateDate: [],
      openStatus: true,
      currendType: '', // 当前发票类型
      personageCommonBill: '', // 个人普通发票
      unitCommonBill: '', // 单位普通发票
      unitAddValueBill: '', // 单位增值税发票
      currentOrderIndex: '', // 当前的订单的行索引
      currentOrderId: '', // 当前的订单的行ID
      searchTaxshhetTest: [],
      searchCondition: {
        GT_createDate: null,
        LT_createDate: null,
        EQ_billingStatus: null,
        EQ_taxsheetType: null,
        LIKE_taxsheetNo: null,
        EQ_taxationPayStatus: null
      },
      dialogTitle: '新增',
      openInvoiceMoneyTitle: '新增',
      openBillTitle: '详情',
      orderTitle: '新增',
      invoiceTitle: '新增',
      condition: {
        name: '',
        number: ''
      },
      tableData: [],
      tableDetailData: [],
      orderData: [],
      invoiceData: [],
      sels: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      sortProp: null,
      sortOrder: 'ascending',
      sels1: [],
      total1: 0,
      currentPage1: 1,
      pageSize1: 10,
      sortProp1: null,
      sortOrder1: 'ascending',
      sels2: [],
      total2: 0,
      currentPage2: 1,
      pageSize2: 10,
      sortProp2: null,
      sortOrder2: 'ascending',
      sels4: [],
      total4: 0,
      currentPage4: 1,
      pageSize4: 10,
      sortProp4: null,
      sortOrder4: 'ascending',
      listLoading1: false,
      openBillVisible: false,
      listLoading: false,
      listLoading2: false,
      listLoading3: false,
      listLoading4: false,
      taxsheetVisible: false,
      orderVisible: false,
      openInvoiceMoneyVisible: false,
      invoiceVisible: false,
      submitLoading: false,
      tempDelDetail: [],
      addDetail2: [],
      // 发票抬头表单数据
      invoiceManage: {
        'id': null,
        'httpHead': null,
        'realName': null,
        'myAddress': [],
        'taxsheetType': null,
        'taxsheetTitle': null,
        'consigneeId': null,
        'consigneeName': null,
        'isActiveBilling': null,
        'phone': null,
        'telphone': null,
        'provinceId': null,
        'province': null,
        'city': null,
        'cityId': null,
        'county': null,
        'countyId': null,
        'town': null,
        'townId': null,
        'street': null,
        'isDefault': null,
        'taxpayersRegistrationNumber': null,
        'openingBank': null,
        'bankAccount': null,
        'registerLocalHost': null,
        'companyTelphone': null,
        'businessLicenseUrl': null,
        'taxpayerProveUrl': null
      },
      // 表单数据
      taxsheet: {
        'id': null,
        'isDel': false,
        'userId': null,
        'billingStatusName': null,
        'taxReceivable': null,
        'myAddress': [],
        delIds: [],
        'billingDate': null,
        'appTaxsheetAmount': null,
        'taxsheetType': null,
        'taxsheetTitle': null,
        'taxsheetTitleId': null,
        'taxsheetTitleIds': '',
        'consigneeId': null,
        'consigneeName': null,
        'phone': null,
        'telphone': null,
        'provinceId': null,
        'cityId': null,
        'countyId': null,
        'street': null,
        'collectAddress': null,
        'isDefault': null,
        'isActiveBilling': null,
        'taxpayersRegistrationNumber': null,
        'openingBank': null,
        'bankAccount': null,
        'registerLocalHost': null,
        'companyTelphone': null,
        'businessLicenseUrl': null,
        'taxpayerProveUrl': null,
        'billingStatus': null,
        'taxsheetDetails': []
        //   'id': null,
        //   'documentType': null,
        //   'invoicePeriodStart': null,
        //   'invoicePeriodEnd': null,
        //   'documentNumber': null,
        //   'documentAmount': null,
        //   'taxMayBeInvoiced': null,
        //   'invoicedAmount': null,
        //   'currentInvoicedAmount': null,
        //   'taxesAndFeesReceivable': null,
        //   'taxsheet': null
        // }
      },
      taxsheetDetails: [],
      // 验证规则
      rules: {
        myAddress: [
          {type: 'array', required: true, message: '请选择地址', trigger: 'change'}
        ],
        taxsheetTitleId: [
          {required: true, message: '请选择发票抬头', trigger: 'change'}
        ],
        consigneeName: [
          {required: true, message: '请输入收件人名称', trigger: 'change'},
          {min: 2, max: 60, message: '长度在2到 60 个字符', trigger: 'change'}
        ],
        street: [
          {required: true, message: '请输入街道', trigger: 'change'},
          {min: 2, max: 60, message: '长度在2-60个字符', trigger: 'change'}
        ]
      }
    };
  },
  watch: {
    searchCreateDate (val) {
      this.searchCondition.GT_createDate = val[0] == null ? null : val[0].toJSON();
      this.searchCondition.LT_createDate = val[1] == null ? null : val[1].toJSON();
    }
  },
  methods: {
    doGetTaxsheetTitleEnValueAddedTax () {
      getTaxsheetTitleEnValueAddedTax().then((res) => {
        if (res.data.successFlg && res.data.obj !== null) {
          this.useEnTaxShow = true;
          this.taxsheetTitleEnValueAddedTaxObj = res.data.obj;
        }
      });
    },
    // 支付税费
    paymentAffirms () {
      switch (this.taxPayRadio) {
        case 'accountPay':
          accountPay({
            orderId: this.notSignOffCurrentData.orderId, // 订单id
            couponId: '', // 优惠券id
            couponUseId: ''// 优惠券领用id
          }).then((res) => {
            window.document.write(res.data);
          });
          break;
        case 'aliPay':
          aliPay(
            this.currentTaxsheetId
          ).then((res) => {
            console.log(res.data);
            window.document.write(res.data);
          });
          break;
        case 'weChatPay':
          wechatPay(this.currentTaxsheetId).then((res) => {
            this.wechatQRCodeDialog = true;
            let com = 'http://qr.liantu.com/api.php?text=';
            let url = com + res.data.obj.codeUrl;
            this.QRCodehtml = '<img style="width: 100%;margin: auto" src=' + url + ' />';
            this.stopPayWeChat = setInterval(() => {
              this.refreshTaxPayWeChat(res.data.obj.serialNo);
            }, 5000);
          });
          break;
        case 'unionPay':
          unionPay(this.currentTaxsheetId).then((res) => {
            console.log(res.data);
            window.document.write(res.data);
          });
          break;
      }
    },
    refreshTaxPayWeChat (val) {
      payments(val).then((res) => {
        if (res.data.obj.successFlg) {
          clearInterval(this.stopPayWeChat);
          this.$message.success('支付成功');
          location.reload();
        }
      });
    },
    // 支付税费弹窗
    paymentConfirmation (index, row) {
      this.currentTaxsheetId = row.id;
      this.taxsheet = Object.assign({}, row);
      this.paymentConfirmationDialog = true;
    },
    // 我的发票删除单条数据操作
    handleDel (index, row) {
      this.$confirm('确认删除该发票吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        delTaxsheet(row.id).then((res) => {
          this.listLoading = false;
          this.$message({
            message: '删除成功！',
            type: 'success'
          });
          this.getTableData();
        });
      }).catch(() => {
      });
    },
    // 表格合计
    getSummaries (param) {
      const {columns, data} = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计:';
          return;
        }
        if (index === 1) {
          sums[index] = '';
          return;
        }
        if (index === 2) {
          sums[index] = '';
          return;
        }
        if (index === 3) {
          sums[index] = '';
          return;
        }
        if (index === 7) {
          sums[index] = '';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return Math.floor((prev + curr) * 100) / 100;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ' 元';
        } else {
          sums[index] = 'N/A';
        }
      });

      return sums;
    },
    executeSubmit () {
      this.taxsheet.taxsheetDetails = this.taxsheetDetails;
      if (this.cruuendTable.length === 0 || this.cruuendTable === null) {
        return this.$message.error('请添加详情');
      }
      if (this.tempDelDetail.length > 0) { // 删除的
        this.taxsheet.delIds = this.tempDelDetail;
      }
      for (let x = 0; x < this.taxsheet.taxsheetDetails.length; x++) {
        if (this.taxsheet.taxsheetDetails[x].currentInvoicedAmount <= 0) {
          return this.$message.error('可开票金额不能小于等于零');
        }
      }
      this.taxsheet.taxsheetTitleId = this.taxsheetTitleEnValueAddedTaxObj.id;
      this.taxsheet.taxsheetType = this.taxsheetTitleEnValueAddedTaxObj.taxsheetType;
      this.taxsheet.street = this.taxsheetTitleEnValueAddedTaxObj.street;

      saveTaxsheet(this.taxsheet).then((res) => {
        this.submitLoading = false;
        if (res.data.successFlg === true) {
          this.taxsheetVisible = false;
          this.getTableData();
          this.$message.success('保存/修改成功！');
        } else {
          this.$message.error(res.data.errorMsg);
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    executeDetailSubmit () {
      this.taxsheet.taxsheetDetails = this.taxsheetDetails;
      if (this.cruuendTable.length === 0 || this.cruuendTable === null) {
        return this.$message.error('请添加详情');
      }
      if (this.tempDelDetail.length > 0) { // 删除的
        this.taxsheet.delIds = this.tempDelDetail;
      }
      for (let x = 0; x < this.taxsheet.taxsheetDetails.length; x++) {
        if (this.taxsheet.taxsheetDetails[x].currentInvoicedAmount <= 0) {
          return this.$message.error('可开票金额不能小于等于零');
        }
      }
      this.submitLoading = true;
      this.taxsheet.taxsheetTitleId = this.taxsheetTitleEnValueAddedTaxObj.id;
      this.taxsheet.taxsheetType = this.taxsheetTitleEnValueAddedTaxObj.taxsheetType;
      this.taxsheet.street = this.taxsheetTitleEnValueAddedTaxObj.street;
      saveTaxsheetSubmit(this.taxsheet).then((res) => {
        this.submitLoading = false;
        if (res.data.successFlg === true) {
          this.taxsheetVisible = false;
          this.getTableData();
          this.$message.success('保存/修改成功！');
        } else {
          this.$message.error(res.data.errorMsg);
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    addressValue (value) {
      if (value) {
        return value;
      } else {
        return null;
      }
    },
    // 新增数据提交
    handleSubmit () {
      if (this.useEnTaxChecked === '1') {
        this.taxsheet.taxsheetType = 102013004;
        this.executeSubmit();
      } else {
        // 表单验证
        this.$refs['taxsheet'].validate((valid) => {
          if (valid) {
            this.taxsheet.taxsheetDetails = this.taxsheetDetails;
            this.taxsheet.provinceId = this.addressValue(this.taxsheet.myAddress[0]);
            this.taxsheet.cityId = this.addressValue(this.taxsheet.myAddress[1]);
            this.taxsheet.countyId = this.addressValue(this.taxsheet.myAddress[2]);
            this.taxsheet.townId = this.addressValue(this.taxsheet.myAddress[3]);
            this.executeSubmit();
          } else {
            return false;
          }
        });
      }
    },
    // 新增数据提交
    saveDetailSubmit () {
      if (this.useEnTaxChecked === '1') {
        this.taxsheet.taxsheetType = 102013004;
        this.executeDetailSubmit();
      } else {
        // 表单验证
        this.$refs['taxsheet'].validate((valid) => {
          if (valid) {
            if (this.taxsheet.myAddress.length === 1) {
              this.taxsheet.provinceId = this.taxsheet.myAddress[0];
            } else if (this.taxsheet.myAddress.length === 2) {
              this.taxsheet.provinceId = this.taxsheet.myAddress[0];
              this.taxsheet.cityId = this.taxsheet.myAddress[1];
            } else if (this.taxsheet.myAddress.length === 3) {
              this.taxsheet.provinceId = this.taxsheet.myAddress[0];
              this.taxsheet.cityId = this.taxsheet.myAddress[1];
              this.taxsheet.countyId = this.taxsheet.myAddress[2];
            } else if (this.taxsheet.myAddress.length === 4) {
              this.taxsheet.provinceId = this.taxsheet.myAddress[0];
              this.taxsheet.cityId = this.taxsheet.myAddress[1];
              this.taxsheet.countyId = this.taxsheet.myAddress[2];
              this.taxsheet.townId = this.taxsheet.myAddress[3];
            } else {
              return this.$message.error('请选择地址!');
            }
            this.executeDetailSubmit();
          } else {
            return false;
          }
        });
      }
    },
    // 删除我的发票详情数据操作
    handleTaxsheetDel (index, row, rows) {
      if (row.id !== '') {
        this.tempDelDetail.push(row.id);
      }
      rows.splice(index, 1);
    },
    // 打开调整金额
    openMonen (index, row) {
      this.currentOpenMoneyIndex = index;
      this.currentTaxMayBeInvoiced = this.taxsheet.taxsheetDetails[index].taxMayBeInvoiced;
      this.openInvoiceMoneyVisible = true;
    },
    // 本次对帐单的调整保存
    saveOpenMoney () {
      this.$refs['openTaxSheet'].validate((valid) => {
        if (valid) {
          if (parseFloat(this.openTaxSheet.currentOpenMoney) > this.currentTaxMayBeInvoiced) {
            return this.$message.error('本次开票金额不能超过可开票含税金额');
          }
          this.taxsheet.taxsheetDetails[this.currentOpenMoneyIndex].currentInvoicedAmount = this.openTaxSheet.currentOpenMoney;
          this.openTaxSheet.currentOpenMoney = '';
          this.currentTaxMayBeInvoiced = '';
          this.currentOpenMoneyIndexMoney = '';
          this.currentOpenMoneyIndex = '';
          this.openInvoiceMoneyVisible = false;
        } else {
          return false;
        }
      });
    },
    setTaxsheetTypeClick (val) {
      if (this.useEnTaxChecked === '0') {
        this.taxsheet.taxsheetTitleId = this.taxsheetTitleEnValueAddedTaxObj.id;
        this.taxsheet.taxsheetType = this.taxsheetTitleEnValueAddedTaxObj.taxsheetType;
        this.taxsheet.street = this.taxsheetTitleEnValueAddedTaxObj.street;
        this.taxsheetTypeSelect(102013004);
      } else {
        resetForm(this.$refs.taxsheet, this.taxsheet);
        //          this.taxsheet.taxsheetTitleId = null;
        //          this.taxsheet.consigneeName = null;
        //          this.taxsheet.myAddress = null;
        //          this.taxsheet.taxsheetType = null;
        //          this.taxsheet.phone = null;
        //          this.taxsheet.street = null;
        if (this.taxsheet.taxsheetDetails !== null) {
          this.taxsheet.taxsheetDetails.forEach(res => {
            if (res.documentType === 102015002) {
              res.taxMayBeInvoiced = 0;
              res.currentInvoicedAmount = 0;
              res.taxesAndFeesReceivable = 0;
            }
          });
        }
      }
    },
    // 发票类型选择时
    taxsheetTypeSelect (event) {
      this.currendType = event;
      if (event === 102013001 && !isEmpty(this.taxsheet.taxsheetDetails)) {
        this.taxsheet.taxsheetDetails.forEach(res => {
          if (res.documentType === 102015002) {
            res.taxMayBeInvoiced = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.personageCommonBill);
            res.currentInvoicedAmount = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.personageCommonBill);
            res.taxesAndFeesReceivable = parseFloat(res.documentAmount) * parseFloat(this.personageCommonBill);
          }
        });
      }
      if (event === 102013002 && !isEmpty(this.taxsheet.taxsheetDetails)) {
        this.taxsheet.taxsheetDetails.forEach(res => {
          if (res.documentType === 102015002) {
            res.taxMayBeInvoiced = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.unitCommonBill);
            res.currentInvoicedAmount = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.unitCommonBill);
            res.taxesAndFeesReceivable = parseFloat(res.documentAmount) * parseFloat(this.personageCommonBill);
          }
        });
      }
      if (event === 102013003 && !isEmpty(this.taxsheet.taxsheetDetails)) {
        this.taxsheet.taxsheetDetails.forEach(res => {
          if (res.documentType === 102015002) {
            res.taxMayBeInvoiced = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.unitAddValueBill);
            res.currentInvoicedAmount = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.unitAddValueBill);
            res.taxesAndFeesReceivable = parseFloat(res.documentAmount) * parseFloat(this.unitAddValueBill);
          }
        });
      }
      if (event === 102013004 && this.useEnTaxChecked === '1' && !isEmpty(this.taxsheet.taxsheetDetails)) {
        this.taxsheet.taxsheetDetails.forEach(res => {
          if (res.documentType === 102015002) {
            res.taxMayBeInvoiced = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.unitAddValueBill);
            res.currentInvoicedAmount = parseFloat(res.documentAmount) + parseFloat(res.documentAmount) * parseFloat(this.unitAddValueBill);
            res.taxesAndFeesReceivable = parseFloat(res.documentAmount) * parseFloat(this.unitAddValueBill);
          }
        });
      }
    },
    orderSave () {
      let tableDetailDatas = [];
      this.sels1.forEach(sel => {
        let tdd = {};
        tdd.documentAmount = sel.orderPrice;
        tdd.documentNumber = sel.orderNumber;
        tdd.documentType = 102015002;
        tdd.documentTypeName = '订单';
        tdd.id = null;
        if (this.currendType === 102013001) {
          tdd.taxMayBeInvoiced = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * parseFloat(this.personageCommonBill); // 个人普通发票
          tdd.currentInvoicedAmount = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * parseFloat(this.personageCommonBill);
          tdd.taxesAndFeesReceivable = parseFloat(sel.orderPrice) * parseFloat(this.personageCommonBill);
        } else if (this.currendType === 102013002) {
          tdd.taxMayBeInvoiced = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice * this.unitCommonBill); // 单位普通发票
          tdd.currentInvoicedAmount = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * this.unitCommonBill;
          tdd.taxesAndFeesReceivable = parseFloat(sel.orderPrice) * parseFloat(this.unitCommonBill);
        } else if (this.currendType === 102013003) {
          tdd.taxMayBeInvoiced = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * parseFloat(this.unitAddValueBill); // 单位增值税普通发票
          tdd.currentInvoicedAmount = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * parseFloat(this.unitAddValueBill);
          tdd.taxesAndFeesReceivable = parseFloat(sel.orderPrice) * parseFloat(this.unitAddValueBill);
        } else if (this.useEnTaxChecked === '1') {
          tdd.taxMayBeInvoiced = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * parseFloat(this.unitAddValueBill); // 企业增值税发票图片
          tdd.currentInvoicedAmount = parseFloat(sel.orderPrice) + parseFloat(sel.orderPrice) * parseFloat(this.unitAddValueBill);
          tdd.taxesAndFeesReceivable = parseFloat(sel.orderPrice) * parseFloat(this.unitAddValueBill);
        } else {
          tdd.taxMayBeInvoiced = 0;
        }
        tdd.invoicedAmount = 0;
        tdd.currentInvoicedAmount = tdd.taxMayBeInvoiced;// 本次开票金额(元)
        if (this.currendType === '') {
          tdd.taxesAndFeesReceivable = 0;
        } else {
          tdd.taxesAndFeesReceivable = tdd.taxMayBeInvoiced - sel.orderPrice; // 本次应收税费(元)
        }
        tdd.isDel = true;
        tableDetailDatas.push(tdd);
      });
      let newArrays = [];
      if (this.taxsheetDetails != null && this.taxsheetDetails.length > 0) {
        newArrays = tableDetailDatas.concat(this.taxsheetDetails);
        let myArrays = uniqeByKeys(newArrays, ['documentNumber']);
        this.taxsheetDetails = myArrays;
      } else {
        this.taxsheetDetails = tableDetailDatas;
      }
      this.cruuendTable = tableDetailDatas;
      this.orderVisible = false;
    },
    saveInvoice () {
      let tableDetailDatas = [];
      this.sels2.forEach(sel => {
        let tdd = {};
        tdd.documentAmount = sel.invoiceTotalAmount;
        tdd.invoicePeriodStart = sel.invoicePeriodStart;
        tdd.invoicePeriodEnd = sel.invoicePeriodEnd;
        tdd.documentNumber = sel.invoiceNumber;
        tdd.documentType = 102015001;
        tdd.documentTypeName = '对帐单';
        tdd.id = null;
        tdd.taxMayBeInvoiced = sel.amountToBeInvoiced;
        tdd.taxesAndFeesReceivable = 0;
        tdd.invoicedAmount = 0;
        tdd.currentInvoicedAmount = 0;
        tdd.isDel = true;
        tableDetailDatas.push(tdd);
      });
      let newArrays = [];
      if (this.taxsheetDetails != null && this.taxsheetDetails.length > 0) {
        newArrays = tableDetailDatas.concat(this.taxsheetDetails);
        this.taxsheetDetails = newArrays;
      } else {
        this.taxsheetDetails = tableDetailDatas;
      }
      this.cruuendTable = tableDetailDatas;
      this.taxsheet.isDel = true;
      this.invoiceVisible = false;
    },
    // 发票抬头赋值
    mySearchTaxsheet (event) {
      if (this.useEnTaxChecked !== '1') {
        let datas = getSelectObect(this.taxsheet.taxsheetTitleId, 'id', this.searchTaxshhetTest);
        if (!isEmpty(datas)) {
          this.taxsheet.taxsheetTitle = datas.taxsheetTitle;
          this.taxsheet.phone = datas.phone;
          this.taxsheet.taxsheetTitleId = datas.id;
          this.taxsheet.consigneeName = datas.consigneeName;
          this.taxsheet.taxsheetType = datas.taxsheetType;
          this.taxsheet.street = datas.street;
          this.taxsheet.myAddress = [datas.provinceId, datas.cityId, datas.countyId];
          this.taxsheetTypeSelect(datas.taxsheetType);
        }
      }
    },
    // 开票抬头搜索
    searchTaxsheets () {
      searchInvoiceManage({
        filters: 'NOTEQ_taxsheetType=102013004;',
        sorts: '',
        size: '15',
        page: '1'
      }).then((res) => {
        this.searchTaxshhetTest = res.data.detailModelList;
      });
      //                }
    },
    // 我的发票 搜索 栏重置
    myReset () {
      this.searchCreateDate = [];
      resetObjNull(this.searchCondition);
    },
    loadingLists (filter) {
      this.listLoading = true;
      searchTaxsheet({
        filters: filter,
        size: this.pageSize,
        page: this.currentPage,
        sorts: (this.sortProp === null ? '' : (this.sortOrder === 'ascending' ? '-' : '+') + this.sortProp)
      }).then(res => {
        if (res.data.successFlg) {
          this.tableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
          this.listLoading = false;
        }
      });
    },
    //      //  搜索栏搜索
    searchTaxsheet () {
      this.loadingLists(objToFilter(this.searchCondition));
    },
    // 打开详情界面
    getEditBYId (index, row) {
      this.resetForm1();
      if (row.taxsheetType === 102013003) {
        getInvoiceManage(row.taxsheetTitleId).then((res) => {
          if (res.data.successFlg) {
            this.invoiceManage = res.data.obj;
          }
        });
      }
      getTaxsheet(row.id).then((res) => {
        if (res.data.successFlg) {
          this.taxsheet = res.data.obj;
        }
      });
      this.openBillTitle = '发票详情';
      this.openBillVisible = true;
    },

    // 新增申请开票窗体
    handleAdd () {
      this.openStatus = true;
      this.orderTitle = '新增';
      this.resetForm();
      this.taxsheetVisible = true;
    },

    // 申请开票编辑窗体
    handleEdit (index, row) {
      this.openStatus = true;
      this.orderTitle = '新增';
      this.resetForm();
      this.taxsheet = Object.assign({}, row);
      this.taxsheet.myAddress = [row.provinceId, row.cityId, row.countyId];
      this.cruuendTable = row.taxsheetDetails;
      if (row.taxsheetType === 102013004) {
        this.useEnTaxChecked = 1;
      }
      this.taxsheetVisible = true;
    },
    // 添加订单窗体
    addOrderDetail () {
      this.getOrderTableDatas();
      this.orderTitle = '新增';
      this.orderVisible = true;
    },
    // 添加对帐单窗体
    addInvoiceDetail () {
      this.getInvoiceTableDatas();
      this.invoiceTitle = '新增';
      this.invoiceVisible = true;
    },
    // 重置我的发票表单
    resetForm () {
      if (this.$refs.taxsheet) {
        this.$refs.taxsheet.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.taxsheet) {
        if (this.taxsheet[p] instanceof Array) {
          this.taxsheet[p] = [];
        } else {
          this.taxsheet[p] = null;
        }
      }
      // 情况明细列表
      this.taxsheetDetails = [];
    },

    // 多选操作
    selsChange (sels) {
      this.sels = sels;
    },
    // 排序操作
    sortChange (o) {
      this.sortProp = o.prop;
      this.sortOrder = o.order;
      this.searchTaxsheet();
    },
    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchTaxsheet();
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchTaxsheet();
    },

    // 多选操作
    selsChange2 (sels) {
      this.sels2 = sels;
    },
    // 排序操作
    sortChange2 (o) {
      this.sortProp2 = o.prop;
      this.sortOrder2 = o.order;
      this.getInvoiceTableDatas();
    },
    // 每页几条操作
    handleSizeChange2 (val) {
      this.pageSize2 = val;
      this.getInvoiceTableDatas();
    },
    // 第几页操作
    handleCurrentChange2 (val) {
      this.currentPage2 = val;
      this.getInvoiceTableDatas();
    },

    // 多选操作
    selsChange1 (sels) {
      this.sels1 = sels;
    },
    // 排序操作
    sortChange1 (o) {
      this.sortProp1 = o.prop;
      this.sortOrder1 = o.order;
      this.getOrderTableDatas();
    },
    // 每页几条操作
    handleSizeChange1 (val) {
      this.pageSize1 = val;
      this.getOrderTableDatas();
    },
    // 第几页操作
    handleCurrentChange1 (val) {
      this.currentPage1 = val;
      this.getOrderTableDatas();
    },
    // 重置表单
    resetForm1 () {
      if (this.$refs.invoiceManage) {
        this.$refs.invoiceManage.resetFields();
      }
      // 当先点击修改，再点击新增，会出现值没有清空,修复处理
      for (let p in this.invoiceManage) {
        if (this.invoiceManage[p] instanceof Array) {
          this.invoiceManage[p] = [];
        } else {
          this.invoiceManage[p] = null;
        }
      }
    },
    // 获取税费
    getFreightAddValue () {
      searchAddValue({
        filters: '',
        size: 100,
        page: 1,
        sorts: ''
      }).then((res) => {
        if (res.data.successFlg) {
          res.data.detailModelList.forEach((res) => {
            if (res.dictValue === 101002005) {
              this.personageCommonBill = res.value;
            }
            if (res.dictValue === 101002006) {
              this.unitCommonBill = res.value;
            }
            if (res.dictValue === 101002007) {
              this.unitAddValueBill = res.value;
            }
          });
        }
      });
    },
    // 获取对帐单表格数据
    getInvoiceTableDatas () {
      this.listLoading4 = true;
      searchByUserId({
        filters: 'invoiceStatus<>102012001;amountToBeInvoiced>0;hasBilling=111002002',
        sorts: '',
        page: this.currentPage2,
        size: this.pageSize2
      }).then((res) => {
        if (res.data.successFlg) {
          this.invoiceData = res.data.detailModelList;
          this.currentPage2 = res.data.currPage;
          this.total2 = res.data.totalCount;
          this.pageSize2 = res.data.pageSize;
          this.listLoading4 = false;
        } else {
          this.$message.error(res.data.errorMsg);
        }
      });
    },
    // 获取订单表格数据
    getOrderTableDatas () {
      this.listLoading2 = true;
      searchOrderForInvoice({
        sorts: '',
        page: this.currentPage1,
        size: this.pageSize1
      }).then((res) => {
        if (res.data.successFlg) {
          this.orderData = res.data.detailModelList;
          this.currentPage1 = res.data.currPage;
          this.total1 = res.data.totalCount;
          this.pageSize1 = res.data.pageSize;
          this.listLoading2 = false;
        } else {
          this.$message.error(res.data.errorMsg);
        }
      });
    },
    // 获取我的发票表格数据
    getTableData () {
      this.listLoading = true;
      searchTaxsheet({
        filters: '',
        sorts: '',
        page: this.currentPage,
        size: this.pageSize
      }).then((res) => {
        if (res.data.successFlg === true) {
          this.tableData = res.data.detailModelList;
          this.currentPage = res.data.currPage;
          this.total = res.data.totalCount;
          this.pageSize = res.data.pageSize;
          this.listLoading = false;
        } else {
          this.$message.error(res.data.errorMsg);
        }
      });
    }

  },
  // 初始化数据
  mounted () {
    this.doGetTaxsheetTitleEnValueAddedTax();
    this.searchTaxsheets();
    this.getFreightAddValue();
    this.getTableData();
    this.$store.commit('initDict');
  }
};
</script>
<style lang="less">

</style>
